package com.ruoyi.web.controller.ucenter.api;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.model.user.dto.LoginUserDto;
import com.ruoyi.ucenter.service.IUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author : 张怀秋
 **/
@Api(tags = "登录接口(这些接口一个接口一个controller)")
@RestController
@RequestMapping("/api/u-center")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class LoginController extends BaseController {
    private final IUserInfoService userInfoService;

    @ApiOperation("账号密码登录")
    @PostMapping("/login/byApp")
    public AjaxResult loginByApp(@RequestBody LoginUserDto loginUserDto) {
        Map<String, Object> result = userInfoService.loginByApp(loginUserDto);
        return AjaxResult.success(result);
    }

    @ApiOperation("短信登录")
    @PostMapping("/login/byPhone")
    public AjaxResult loginByPhone(@RequestBody LoginUserDto loginUserDto) {
        Map<String, Object> result = userInfoService.loginByPhone(loginUserDto);
        return AjaxResult.success(result);
    }

    @ApiOperation("邮箱登录")
    @PostMapping("/login/byMail")
    public AjaxResult loginByMail(@RequestBody LoginUserDto loginUserDto) {
        Map<String, Object> result = userInfoService.loginByMail(loginUserDto);
        return AjaxResult.success(result);
    }
}
